﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Martin.WcfService.Services;
using Martin.WcfService.Contracts;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace Martin.WcfService.Hosting
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(typeof(CalculatorService)))
            {
                #region Using code to implement
                //host.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "http://localhost:168/wcfdemo");
                //if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
                //{
                //    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                //    behavior.HttpGetEnabled = true;
                //    behavior.HttpGetUrl = new Uri("http://localhost:168/calculatorservice/metadata");
                //    host.Description.Behaviors.Add(behavior);
                //}
                #endregion

                #region Using config to implement
                //no code need to write
                //^_^
                #endregion
                host.Opened += delegate
                {
                    Console.WriteLine("CalculaorService已经启动，按任意键终止服务！");
                };
                host.Open();
                host.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(host_UnknownMessageReceived);
                Console.Read();
            }
        }

        static void host_UnknownMessageReceived(object sender, UnknownMessageReceivedEventArgs e)
        {
            Console.WriteLine(sender.GetType().ToString());

        }
    }
}
